package 寒假作业.LeetCode;

public class Num1816 {
    public String truncateSentence(String s, int k) {
        if (s.length() == 0){
            return null;
        }
        String ret = "";
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == ' ' && k > 0){
                k--;
            }
            if(k == 0){
                ret = s.substring(0,i);
                break;
            }
        }
        if(k != 0){
            return s;
        }
        return ret;
    }
}
